"""MxShop URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from django.urls import path, include
from MxShop.settings import MEDIA_ROOT
from django.views.static import serve
from rest_framework.documentation import include_docs_urls
from rest_framework.routers import DefaultRouter
from rest_framework_jwt.views import obtain_jwt_token

from goods.views import GoodsListViewSet,CategoryViewSet
from users.views import SmsCodeViewSet,UserViewSet
from user_operation.views import UserFavViewSet, LeavingMessageViewSet, AddressViewset

router = DefaultRouter()
router.register(r'goods',GoodsListViewSet,basename='goods')
router.register(r'categorys',CategoryViewSet,basename='categorys')
router.register(r'code',SmsCodeViewSet,basename='code')
router.register(r'users',UserViewSet,basename='users')
router.register(r'userfavs',UserFavViewSet,basename='userfavs')
router.register(r'messages', LeavingMessageViewSet,basename='messages')
router.register(r'address',AddressViewset,basename='address')

urlpatterns = [
    url('admin/', admin.site.urls),
    url('^api-auth/', include('rest_framework.urls')),
    url('^docs/', include_docs_urls(title="生鲜超市")),  # drf api
    url(r'^',include(router.urls)),
    url(r'media/(?P<path>.*)$', serve, {"document_root": MEDIA_ROOT}),
    # jwt的token认证接口
    url('^login/', obtain_jwt_token,name="login")
]
